<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-3-5
 */

namespace Zhub\HttpMessage\Headers;


use Zhub\DataStruct\Maps\StringMap;
use Zhub\DataStruct\Struct;

abstract class HeaderStruct extends Struct
{
    const HEADER = 'header';

    const COOKIE = 'cookie';

    public static function initialize(): array
    {
        return [
            self::HEADER => function () {return StringMap::class;},
            self::COOKIE => function () {return StringMap::class;},
        ];
    }

    public function getHeaderMap():StringMap
    {
        return $this->get(self::HEADER);
    }
    public function setHeaderMap(StringMap $headers)
    {
        $this->set(self::HEADER, $headers);
    }
    abstract public function getCookieMap();
    abstract public function setCookieMap();

    public function toString(): string
    {
        $headers = $this->getHeaderMap()->each(function (string $key, string $val) {
            return ucwords(strtolower($key), '-_'). ': ' . $val;
        });
        return implode("\n", $headers);
    }
}
